home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0787.arc / IWPAS.ARC / SERIAL.P < prev    next >
Encoding:
Text File  |  1987-04-28  |  2.9 KB  |  104 lines

  1. { SERIAL.P -- serial interface code                     }
  2.  
  3. { Copyright (c) 1987, Ciarcia's Circuit Cellar          }
  4. {    All Rights Reserved                                }
  5.  
  6.  
  7. {-------------------------------------------------------}
  8. { Global constants                                      }
  9.  
  10. CONST
  11.  
  12.  maxtime   = 100;                      { serial timeout }
  13.  
  14. {-------------------------------------------------------}
  15. { Global variables                                      }
  16.  
  17. VAR
  18.  COMerror  : INTEGER;
  19.  
  20. {-------------------------------------------------------}
  21. { Async card global constants                           }
  22.  
  23. CONST
  24.  
  25.  XON       = $11;
  26.  XOFF      = $13;
  27.  
  28.  DataReady = $01;               { receive data ready    }
  29.  THRE      = $20;               { transmit data ready   }
  30.  
  31. {-------------------------------------------------------}
  32. { Async card global variables                           }
  33.  
  34. VAR
  35.  
  36.  comdata : INTEGER;             { data for async I/O    }
  37.  comien  : INTEGER;             { interrrupt enable reg }
  38.  comiir  : INTEGER;             { interrupt ID reg      }
  39.  comlcr  : INTEGER;             { line control reg      }
  40.  commcr  : INTEGER;             { modem control reg     }
  41.  comlsr  : INTEGER;             { line status reg       }
  42.  commsr  : INTEGER;             { modem status reg      }
  43.  
  44. {-------------------------------------------------------}
  45. { Set up the async card                                 }
  46. { Rate is in bits/second                                }
  47.  
  48. PROCEDURE ComOn(rate : INTEGER);
  49.  
  50. CONST
  51.  serialmax = 115200.0;          { rate -> divisors      }
  52.  
  53. VAR
  54.  dummy     : BYTE;
  55.  counts    : INTEGER;
  56.  
  57. BEGIN
  58.  
  59. {--- set up global variables                            }
  60.  
  61.  comdata := comport;
  62.  comien  := comport + 1;
  63.  comiir  := comport + 2;
  64.  comlcr  := comport + 3;
  65.  commcr  := comport + 4;
  66.  comlsr  := comport + 5;
  67.  commsr  := comport + 6;
  68.  
  69. {--- set up port registers                              }
  70.  
  71.  counts := Trunc(serialmax/rate);
  72.  
  73.  Port[comlcr]  := $80;          { set DLAB to set rate  }
  74.  Port[comdata] := Lo(counts);   { set divisor LSB       }
  75.  Port[comien]  := Hi(counts);   { set divisor MSB       }
  76.  Port[comlcr]  := $13;          {   no pty 1 stop 8 dat }
  77.  
  78.  dummy := Port[comdata];        { discard pending char  }
  79.  
  80. END;
  81.  
  82.  
  83. {-------------------------------------------------------}
  84. { Send a byte to the serial port                        }
  85. { If there's an XOFF in the receiver, we wait...        }
  86. { This is not likely, but it has been known to happen   }
  87.  
  88. PROCEDURE SendByte(databyte : BYTE);
  89.  
  90. BEGIN
  91.  
  92.  COMerror := 0;                 { can't have error...   }
  93.  
  94.  WHILE (Port[comlsr] AND THRE) = 0 DO;    { send done?  }
  95.  
  96.  WHILE Port[comdata] = XOFF DO; { XOFF pending?         }
  97.  
  98.  Port[comdata] := databyte;     { send data             }
  99.  
  100. END;
  101.  
  102.  
  103.  
  104.